package com.le.tester.book.effectivejava3rdchinese.articlefortytwo;

import com.le.tester.javaThink.fourth.net.mindview.util.Print;

import java.util.function.DoubleBinaryOperator;

/**
 * createTime：2022/8/24 13:47
 * description：lambda表达式优于匿名类
 */
public enum Operation {
    PLUS("+", Double::sum),
    MINUS("-", (x, y) -> x - y),
    TIMES("*", (x, y) -> x * y),
    DIVIDE("/", (x, y) -> x / y);


    private final String symbol;

    private final DoubleBinaryOperator op;

    Operation(String symbol, DoubleBinaryOperator op) {
        this.symbol = symbol;
        this.op = op;
    }

    @Override
    public String toString() {
        return symbol;
    }

    public double apply(double x, double y) {
        return op.applyAsDouble(x, y);
    }
}
